package com.newjiabo.web.controller.ski;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.newjiabo.common.annotation.RepeatSubmit;
import com.newjiabo.ski.domain.SkiMealSnowRel;
import com.newjiabo.ski.domain.SkiSnowField;
import com.newjiabo.ski.domain.dto.SkiSnowFieldDTO;
import com.newjiabo.ski.service.ISkiMealSnowRelService;
import com.newjiabo.ski.service.ISkiSnowFieldInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newjiabo.common.annotation.Log;
import com.newjiabo.common.core.controller.BaseController;
import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.common.enums.BusinessType;
import com.newjiabo.common.utils.poi.ExcelUtil;
import com.newjiabo.common.core.page.TableDataInfo;

/**
 * 雪场信息Controller
 *
 * @author ruoyi
 * @date 2023-09-18
 */
@RestController
@RequestMapping("/system/snowField")
@Api(tags = "后台;雪场信息")
public class SkiSnowFieldController extends BaseController {

    @Resource
    private ISkiSnowFieldInfoService skiSnowFieldInfoService;
    @Resource
    private ISkiMealSnowRelService skiMealSnowRelService;

    /**
     * 查询雪场信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询雪场信息列表")
    public TableDataInfo list(SkiSnowField skiSnowField) {
        startPage();
        List<SkiSnowField> list = skiSnowFieldInfoService.selectSkiSnowFieldList(skiSnowField);
        return getDataTable(list);
    }

    /**
     * 导出雪场信息列表
     */
    @ApiOperation(value = "导出雪场信息列表")
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "导出雪场信息列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkiSnowField skiSnowField) {
        List<SkiSnowField> list = skiSnowFieldInfoService.selectSkiSnowFieldList(skiSnowField);
        ExcelUtil<SkiSnowField> util = new ExcelUtil<SkiSnowField>(SkiSnowField.class);
        util.exportExcel(response, list, "雪场信息数据");
    }

    /**
     * 获取雪场信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取雪场信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(skiSnowFieldInfoService.selectSkiSnowFieldInfoById(id));
    }

    /**
     * 新增雪场信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "新增雪场信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增雪场信息")
    public AjaxResult add(@RequestBody @Validated SkiSnowFieldDTO skiSnowFieldDTO) {
        return toAjax(skiSnowFieldInfoService.addSnowField(skiSnowFieldDTO));
    }

    /**
     * 修改雪场信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "修改雪场信息", businessType = BusinessType.UPDATE)
    @PutMapping("/{snowFieldId}")
    @ApiOperation(value = "修改雪场信息")
    public AjaxResult edit(@PathVariable("snowFieldId") String snowFieldId,@RequestBody @Validated SkiSnowFieldDTO skiSnowFieldDTO) {
        return toAjax(skiSnowFieldInfoService.updateSnowField(snowFieldId,skiSnowFieldDTO));
    }

    /**
     * 删除雪场信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "删除雪场信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除雪场信息")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(skiSnowFieldInfoService.deleteSkiSnowFieldByIds(ids));
    }

    @ApiOperation(value = "关联雪场和套餐")
    @PostMapping("/rel/add")
    public AjaxResult rel(@RequestBody List<SkiMealSnowRel> relList){
        return toAjax(skiMealSnowRelService.saveBatch(relList));
    }

}
